package com.keyinong.caizhengting.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.keyinong.caizhengting.R;

import java.util.ArrayList;

public class NoticeDateSelectedAdapter extends BaseAdapter {
    private ArrayList<String> list;
    private Context context;

    public NoticeDateSelectedAdapter(ArrayList<String> list, Context context) {
        super();
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHandler handle;
        if (view == null) {
            handle = new ViewHandler();
            view = LayoutInflater.from(context).inflate(
                    R.layout.item_grid_selecteddate, null);
            handle.tv_date = (TextView) view.findViewById(R.id.tv_selectedDate);
            view.setTag(handle);
        } else {
            handle = (ViewHandler) view.getTag();
        }
        String seldate = list.get(position);
        String monthday = seldate.substring(5, seldate.length()).replace(
                "-", "/");
        handle.tv_date.setText(monthday);
        return view;
    }

    private class ViewHandler {
        TextView tv_date;
    }

}
